package com.assistant.codegen.modules.model.domain.column.sub;

import com.assistant.codegen.modules.model.domain.column.ModelColumn;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.ToString;

import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import java.sql.ResultSet;
import java.sql.SQLException;

@NoArgsConstructor
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@Data
@Entity
@DiscriminatorValue("integer")
public class IntegerColumn extends ModelColumn {

    private Integer length = 11;

    @Override
    public Class<Integer> getJavaType() {
        return Integer.class;
    }

    @Override
    public String getColumnTypeDefinition() {
        return "int(" + this.length + ")";
    }

    public IntegerColumn(ResultSet resultSet) throws SQLException {
        super.assign(resultSet);
        this.length = resultSet.getInt("COLUMN_SIZE");
    }
}
